package stu.day19_day24.day24;

import java.util.Arrays;
import java.util.Scanner;

public class hw3 {

    public static void main1(int n,int m,int x) {

        long left = 0;
        long right = m + 1;

        while (left < right) {
            long mid = left + (right - left) / 2;
            if (calTotalHeight(n, x, mid) > m) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }

        System.out.println("ta: "+(left-1));
    }

    public static long calTotalHeight(long n, long x, long k) {
        long total = n;
        total += (Math.max(1, k - x) + k - 2) * Math.min(x - 1, k - 2) / 2;
        total += (Math.max(1, (k - 1) - (n - x)) + k - 1) * Math.min(k - 1, n - x + 1) / 2;
        return total;
    }




    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] arr = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        int n = arr[0];
        int m = arr[1];
        int x = arr[2];

        int left = 1;
        int right = m;
        while (left<right){
            int mid = (left+right)/2;
            int allH = cal(mid,n,x);
            if(allH>m){
                right = mid;
            }else {
                left = mid+1;
            }
        }

        System.out.println("wo: "+(right-1));
        main1(n,m,x);


    }


    public static int cal(int h,int n,int x){
        int sum = h;

            int num = h;
            for(int i=x;i<n;i++){
                if(num>1){
                    num -= 1;
                    sum += num;
                } else if (num==1) {
                    sum += num;
                }
            }

            int h1 = h;
            for(int i=x;i>1;i--){
                if(h1>1){
                    h1 -= 1;
                    sum += h1;
                } else if (h1==1) {
                    sum += h1;
                }
            }

        return sum;
    }


}
